﻿<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>U8檢查首爾標籤</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">	
    <link rel="stylesheet" href="./4/lumen/bootstrap.css" media="screen">
    <link rel="stylesheet" href="./_assets/css/custom.min.css">
  </head>
  <body>
  <div class="container" style='position:fixed; left:30px; top:30px;'>
	<form id="myform">
	<div class="form-group row" >
		<table>
		<tr>
			<th>
				<input type="checkbox" id="check" />
			</th> 
			<th><h5>是否检验D标<h5></th>
		</tr>
		</table>
	</div>
	  <fieldset>
		<h5>U8檢查首爾標籤</h5>
		<!--button type="button" id="btnNext" class="btn btn-primary">下一箱</button-->
		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">目前箱號:</label>
		  <div class="col-sm-10">
		  <input class="form-control" placeholder="1S,M443HZ62,18000,18408T404K,7250860,SAW8C22B-IZ" id="box" type="text">
		  </div>
		</div>	

		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">D标:</label>
		  <div class="col-sm-8">
		  <input class="form-control" placeholder="[)><RS>06<GS>1PS1WM-3030278006-0000004S-00001<GS>33PM443HZ62<GS>1T18408T404K<GS>10D1815<GS>Q18000<GS>4LCN<RS><EOT>" id="D_sign" type="text">
		  </div>
		   <div class="col-sm-2">
		   <input readonly="" class="form-control-plaintext" id="msg0" value="" type="text">
		  </div>
		</div>	
		
		
		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">目前卷盤:</label>
		  <div class="col-sm-8">
		  <input class="form-control" placeholder="M443HZ62,4500,18404T81AB,047,003,7250860,SAW8C22B-IZ" id="diskNow" type="text">
		  </div>
		  <div class="col-sm-2">
		   <input readonly="" class="form-control-plaintext" id="msg" value="" type="text">
		  </div>
		</div>	
		
		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">卷盤D标:</label>
		  <div class="col-sm-8">
		  <input class="form-control" placeholder="[)><RS>06<GS>1PS1WM-3030278006-0000004S-00001<GS>33PM443HZ62<GS>1T18404T81AB<GS>10D1814<GS>Q4500<GS>4LCN<RS><EOT> " id="disk_D_sign" type="text">
		  </div>
		   <div class="col-sm-2">
		   <input readonly="" class="form-control-plaintext" id="msg1" value="" type="text">
		  </div>
		</div>	 
		
		<div class="row">
			<div class="col-md-12">
				<table class="table table-hover" id="dats_table">
					<thead>
						
				 	</thead>
				 	<tbody>
						
				 	</tbody>
				</table>
			</div>
		</div>
	
	</form>	
	<p class="lead">
    <a class="btn btn-primary btn-lg" href="index.html" role="button">返回</a>
	</p>
	</div>
    <script src="./_vendor/jquery/dist/jquery.min.js"></script>
    <script src="./_vendor/popper.js/dist/umd/popper.min.js"></script>
    <script src="./_vendor/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="./_assets/js/custom.js"></script>
	<script>
	var disks = new Array();
	var cks=new Array(); //用来判断卷盘是否有被扫过
	var D_signString = new Array();
	var disk_D_signString = new Array();
	var cksA;//总卷盘标号和（1+2+3）
	var cksB;//外箱编号总和结合cksA进行对比数值相等代表所以卷盘扫描结束光标跳到第一行
	var dk;
	var disksnumber ;
		$("#box").keypress(function(e){    //
		  console.log($("#box").val());
		  var key = e.which;
		  if (key == 13) { 
		  cksA=0;
		  cksB=0;
		 
		  $(msg).val("");
		  $(D_sign).val("");
		  $(msg0).val("");
		   $("#diskNow").val("");
			$.ajax({ 
					url: "getDisk_u8_1.php?lot="+$("#box").val(), 
					dataType : "json",
					success: function(data){
					console.log(data);
					disksnumber = data.length;
					$("#dats_table tbody").empty();//清空表单内容
					var	i;
					//data[data.length]="";
					if(data.length%2==0){
						for(i=0;i<data.length;i=i+2){//一行放两个卷盘
								var disk = $("<td id='"+'d_sign'+i+"'></td>").append("卷盘"+(i+1));
								var idTd = $("<td id='"+'d'+i+"'></td>").append(data[i]);
								var disk1 = $("<td></td>").append("卷盘"+(i+2));
								var idTd1 = $("<td id='"+'d'+(i+1)+"'></td>").append(data[i+1]);
								cksA=cksA+i+1;
								cksA=cksA+i+2;
								$("<tr></tr>")
								.append(disk).append(idTd).append(disk1).append(idTd1)
								.appendTo("#dats_table tbody"); 
								cks[i]="N";
								cks[i+1]="N";
						}
					}
					if(data.length%2==1){
						for(i=0;i<data.length-1;i=i+2){
						
								var disk = $("<td id='"+'d_sign'+i+"'></td>").append("卷盘"+(i+1));
								var idTd = $("<td id='"+'d'+i+"'></td>").append(data[i]);
								var disk1 = $("<td></td>").append("卷盘"+(i+2));
								var idTd1 = $("<td id='"+'d'+(i+1)+"'></td>").append(data[i+1]);
								cksA=cksA+i+1;
								cksA=cksA+i+2;
								$("<tr></tr>")
								.append(disk).append(idTd).append(disk1).append(idTd1)
								.appendTo("#dats_table tbody"); 
								cks[i]="N";
								cks[i+1]="N";
							
						}
						
							var disk = $("<td></td>").append("卷盘"+(data.length));
							var idTd = $("<td id='"+'d'+i+"'></td>").append(data[data.length-1]);
							
							cksA=cksA+i+1;
							
							$("<tr></tr>")
							.append(disk).append(idTd)
							.appendTo("#dats_table tbody"); 
							cks[i]="N";
							
					}
					
					
				}
			});
			if(document.getElementById("check").checked){
				$( "#D_sign" ).focus();
			}
			else{
		   $("#diskNow" ).focus();
			}		
		 }
		});	
	
		  $("#D_sign").keypress(function(e){
		  console.log($("#D_sign").val());
		
		  var d_sign=$("#D_sign").val();
		  D_signString = d_sign.split("<GS>");
		  
		  var key = e.which;
		  var boxnew = $(box).val();
		  if (key == 13) {
				console.log(D_signString);
			$.ajax({ 
					url: "getDisk_u8_4.php?lot="+$("#D_sign").val(), 
					dataType : "json",
					success: function(data){
						console.log(data);
						console.log(data[0]);
						$(msg).val("");
						if(data[0]==$("#box").val()){//通過D_sign找出面前箱號進行匹配
							$("#diskNow").select();
							$(msg0).val("驗證通過").css('color', 'green');
						}
						else{
							$(msg0).val("驗證失敗").css('color', 'red');
						}
					}
				});
			}
		  });
	
	
	$("#diskNow").keypress(function(e){
		  
	
		  dk=$("#diskNow").val();
		  var key = e.which;
		  var ss;
		  
		  if (key == 13) { 
			$(msg).val("");
			$(msg0).val("");
			$(msg1).val("");
			$.ajax({ 
					url: "getDisk_u8_5.php?lot="+$("#diskNow").val(), 
					dataType : "json",
					async: false,
					success: function(data){
						console.log(data);
						console.log(data[0]);
						dk=data[0];
						//data[data.length]="";
						for(ss=0;ss<disksnumber;ss++){
						var id="d"+ss;
						var keys=document.getElementById(id).innerHTML;
						console.log(dk);
						var dks= dk.split("-");
						var keyss=keys.split("-");
						if(dk==keys||(dks[0]==keyss[0]&&dks[3]==keyss[1])){//外箱键盘与内箱卷盘就行匹配,如果匹配不上可能以前的
							//$("#d"+ss).css('color', 'green');              存货编码不一样就对其进行拆分（头尾）比较
							if(cks[ss]!='Y'){
								cksB=cksB+ss+1;
								cks[ss]='Y' ;
							}
							if(document.getElementById("check").checked){
								$("#disk_D_sign").select();
								
							}
							else{
								$("#diskNow").select();
								$("#d"+ss).css('color', 'green');
								if(cksA==cksB){
									$("#box").select();
								}
							}
							$(msg).val("驗證通過").css('color', 'green');
							break;
						}
						else{
							$(msg).val("驗證失敗").css('color', 'red');
							$("#diskNow").select();
						}
					}
				}
			});
			}
		  });
	
	
		$("#disk_D_sign").keypress(function(e){
		  console.log($("#disk_D_sign").val());
		  
		  var dds=$("#disk_D_sign").val();
		  disk_D_signString = dds.split("<GS>");
		  var key = e.which;
		  var D_signs = new Array();
		  
		  if (key == 13) { 
			$(msg).val("");
			$(msg0).val("");
			$(msg1).val("");
			
				$.ajax({ 
					url: "getDisk_u8_6.php?lot="+$("#disk_D_sign").val(), 
					dataType : "json",
					success: function(data){
						console.log(data);
						console.log(data[0]);
						D_disk=data[0];
						diskss=data[1];
						//data[data.length]="";
						for(var ss=0;ss<disksnumber;ss++){
						var id="d"+ss;
						var keys=document.getElementById(id).innerHTML;
							//alert(diskss+"--"+keys);
							//alert(D_disk+"--"+$("#diskNow").val());
							//a.toLowerCase()==b.toLowerCase()
							if(diskss.toLowerCase()==keys.toLowerCase()&&D_disk.toLowerCase()==$("#diskNow").val().toLowerCase()&&disk_D_signString[1]==D_signString[1]){
								$("#d"+ss).css('color', 'green');
						
								$(msg1).val("驗證通過").css('color', 'green');
								
								$("#diskNow").select();
								break;
				
							}
							else{
								$(msg1).val("驗證失敗").css('color', 'red');
								$("#disk_D_sign").select();
							}
						}
						if(cksA==cksB){
							$("#box").select();
						}
					}
				});
			
			}
		  });	
	
	
			
	
			$("#btnNext").click(function(){
				if (("Y"==cks[0]) && ("Y"==cks[1])&&("Y"==cks[2])&&("Y"==cks[3])){
					$(disk1).css('color', 'black');
					$(disk1).val("");
					$(disk2).css('color', 'black');
					$(disk2).val("");
					$(disk3).css('color', 'black');
					$(disk3).val("");
					$(disk4).css('color', 'black');
					$(disk4).val("");
					
					$( "#box" ).val("");
					$( "#box" ).focus();
					
				}
			  
			});	
	</script>

  </body>
</html>
